from django.db import models

class Customer(models.Model):
    TYPE_CHOICES = (
        ('A', 'Admin'),
        ('N', 'Normal'),
    )
    type = models.CharField(max_length=1, choices=TYPE_CHOICES, default='N')
    friends = models.ManyToManyField('self')
    
    moneySpent = models.PositiveIntegerField(default=0)
    
    objects = models.Manager() # avoid pydev warnings
    
    def __str__(self):
        return "Customer(%s)" % self.id

class AdditionalCustomerData(models.Model):
    customer = models.ForeignKey(Customer, null=True)
    name = models.CharField(max_length=100, unique=True)
    
    objects = models.Manager() # avoid pydev warnings
    
class CustomerGroup(models.Model):
    '''Group of players.'''
    name = models.CharField(max_length=100, unique=True)
    customers = models.ManyToManyField(Customer, related_name = 'groups')
    
    objects = models.Manager() # avoid pydev warnings
    
    

class Product(models.Model):
    name = models.CharField(max_length=100, unique=True)
    num_available = models.PositiveIntegerField(default=0)
    
    objects = models.Manager() # avoid pydev warnings
    
class ProductInstance(models.Model):
    buyer = models.ForeignKey(Customer)
    product = models.ForeignKey(Product)
    date = models.DateTimeField()
    quantity = models.PositiveIntegerField(default=0)
    
    objects = models.Manager() # avoid pydev warnings
    
    class Meta:
        unique_together = ('buyer', 'product')